public class StringExtractorContext {
    private State currentState;       // 当前状态
    private StringBuilder result;     // 提取的字符串结果
    private char currentChar;         // 当前处理的字符
    private boolean isCompleted;      // 是否完成提取

    // 初始化：默认进入“等待字符串开始”状态
    public StringExtractorContext() {
        this.currentState = new WaitingForStartState();
        this.result = new StringBuilder();
        this.isCompleted = false;
    }

    // 对外提供的“处理单个字符”方法
    public void processChar(char c) {
        if (isCompleted) return; // 提取完成后不再处理
        this.currentChar = c;
        currentState.handle(this); // 交给当前状态处理
    }

    // 获取最终提取结果
    public String getResult() {
        return result.toString();
    }

    // 以下是getter/setter（供状态类操作）
    public State getCurrentState() {
        return currentState;
    }

    public void setCurrentState(State currentState) {
        this.currentState = currentState;
    }

    public char getCurrentChar() {
        return currentChar;
    }

    public StringBuilder getResultBuilder() {
        return result;
    }

    public boolean isCompleted() {
        return isCompleted;
    }

    public void setCompleted(boolean completed) {
        isCompleted = completed;
    }
}